package com.tarena.lbs.basic.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.basic.dao.mapper.AreaMapper;
import com.tarena.lbs.basic.dao.repository.AreaRepository;
import com.tarena.lbs.basic.pojo.param.AreaParam;
import com.tarena.lbs.basic.pojo.po.AreaPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Slf4j
public class AreaRepositoryImpl implements AreaRepository {
    @Autowired
    AreaMapper mapper;

    @Override
    public List<AreaPO> areaList(Integer parentId) {
        QueryWrapper<AreaPO> qu = new QueryWrapper<>();
        if (parentId != null && parentId>0) {
            qu.eq("parent_id", parentId);
        }else{
            qu.eq("depth",1);
        }
        return mapper.selectList(qu);
    }

    @Override
    public List<AreaPO> cityList(AreaParam param) {
        QueryWrapper<AreaPO> qu = new QueryWrapper<>();
        if (param.getDepth() != null && param.getDepth()>0) {
            qu.eq("depth", param.getDepth());
        }
        return mapper.selectList(qu);
    }
    @Override
    public List<AreaPO> areaAllList() {
        QueryWrapper<AreaPO> qu = new QueryWrapper<>();
        return mapper.selectList(qu);
    }
}
